<?php
// +----------------------------------------------------------------------
// | Jqcms [ Avenue to Jane ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017 http://jqcms.net All rights reserved.
// +----------------------------------------------------------------------
// | Author: hyacinth <845077398@qq.com>
// +----------------------------------------------------------------------
namespace Admin\Controller;
use Common\Controller\BaseController;

class PageController extends BaseController {
    
    public function index(){
       
        $apage = M('Page');
        $where = "";
        $count = $apage->where($where)->count();
        $p = getpage($count,10);
        $list = $apage->field(true)->where($where)->order('id desc')->limit($p->firstRow, $p->listRows)->select();
        $this->assign('list', $list); 
        $this->assign('page', $p->show());
        $this->display();
        
    }

    public function create(){
        
        $apage= D('Page');
        if(IS_POST){
            
            if($apage->create()){
                $apage->add();
                $this->success('添加成功!','index');
            }else{
                $this->error($apage->getError());
            }
        }else{
            $this->display();
        }
           
    }
    //编辑
    public function edit($id){
        
        $apage = D('Page');
        if (IS_POST) {
            
            if($apage->create()){
                $apage->save();
                $this->success('编辑成功!','index');
            }else{
                $this->error($apage->getError());  
            }
             
        }else {
            $data = $apage->find($id);
            $this->assign('data',$data);
            $this->display();
        }
        
    }
    
    //单删 
    public function del($id){
    
        $page = M('Page');
        $del = $page->delete($id);
        
        if($del !==0 && $del !==false){
            $this->success('删除成功!');
        }else {
            $this->error('删除失败!');
        }
         
    }
    //多删
    public function delselect(){
        
        $page = M('Page');
        $idarr = I('id');
        $idstr = implode(',',$idarr);
        $del = $page->delete($idstr);
        
        if($del !==0 && $del !==false){
            $this->success('删除成功!');
        }else {
            $this->error('删除失败!');
        }
         
    }
    
  
    
}